// Package cmd /*
package cmd

import (
	"github.com/spf13/cobra"
	"log"
	"remote_exec/goterm/term"
	"remote_exec/util"
)

var putCmd = &cobra.Command{
	Use:     "put [flags] [section]",
	Short:   "put file to remote",
	Long:    "put file to remote",
	Example: "remote put",
	Run: func(cmd *cobra.Command, args []string) {
		var (
			err       error
			hosts     []*util.Host
			files     []string
			thread, _ = cmd.Flags().GetInt(util.ConstThread)
			netMask   string
		)
		if files, netMask, err = ObtainCommands(cmd, args, "put"); err != nil {
			log.Println(term.Redf(err.Error()))
			return
		}
		if hosts, err = ObtainHosts(cmd, args, netMask); err != nil {
			log.Println(term.Redf(err.Error()))
			return
		}

		log.Println("start put file...")
		util.Process(thread, hosts, func(host *util.Host) {
			util.RemotePut(host, files)
		})
		log.Println(term.Greenf("put file finished."))
	},
}

func init() {
	SetCommonFlags(putCmd)
	rootCmd.AddCommand(putCmd)
}
